import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:learn_flutter/utils/http_request.dart';

main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(primaryColor: Colors.teal, cardColor: Colors.orange),
      debugShowCheckedModeBanner: false,
      home: HYHomePage(),
    );
  }
}

class HYHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Flutter Demo'),
      ),
      body: HYHomeContent(),
      backgroundColor: Colors.white,
      floatingActionButton: FloatingActionButton(
          child: Icon(
            Icons.add,
//            color: Colors.orange,
          ),
          backgroundColor: Colors.teal,
          onPressed: () {
            print('FloatingActionButton click');
          }),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
    );
  }
}

class HYHomeContent extends StatefulWidget {
  @override
  _HYHomeContentState createState() => _HYHomeContentState();
}

class _HYHomeContentState extends State<HYHomeContent> {
  @override
  void initState() {
    super.initState();

    //发送网络请求
    //1.创建Dio
    final dio = Dio();

    //2.发送网络请求
    // dio.get('https://httpbin.org/get').then((value) => print(value));
    // dio.post('https://httpbin.org/post').then((value) => print(value));

    HttpRequest.request('/get', params: {'name': 'zs'},interceptor: Interceptor())
        .then((value) => print(value));
  }

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}
